package com.yyk.yykywd.mvvm.view_model

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.yyk.yykywd.bean.BaseBean

/**
 * 文件描述：
 * Created by guo on 2019-11-13.
 */
open class BaseViewModel : ViewModel() {
    var page = 1
    var num = 20
    var isClear = false

    // The internal MutableLiveData that stores the status of the most recent request
    protected val _status = MutableLiveData<BusinessApiStatus>()

    // The external immutable LiveData for the request status
    val status: LiveData<BusinessApiStatus>
        get() = _status

    var error = MutableLiveData<String>()
    var base = MutableLiveData<BaseBean>()

    fun onError(e: String) {
        error.value = e
    }

    fun setBaseValue(baseBean: BaseBean) {
        base.value = baseBean
    }

    fun loadMore() {
        page++
    }

    fun <T> refresh(list: MutableList<T>) {
        page = 1
        list.clear()
    }

}

enum class BusinessApiStatus { LOADING, ERROR, DONE,EMPTY }